#include "game.h"

SDL_Surface* screen;
signed running;

SDL_Rect **retriveValidModes(Uint32 flags) {
    SDL_Rect **modes;
    modes = SDL_ListModes(NULL, flags);
}

void initSDL(Sint32 width, Sint32 height, Uint32 flags, char *title) {
    if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
        fprintf(stderr, "Can't initialize video system\n");
        exit(1);
    }

    if(retriveValidModes(flags) == (SDL_Rect**) 0) {
        fprintf(stderr, "No video mode avaible\n");
        exit(1);
    }

    screen = SDL_SetVideoMode(width, height, 16, flags); 
   
    if(!screen) {
        fprintf(stderr, "Cannot initialize screen\n");
        exit(1);
    }

    SDL_WM_SetCaption(title, (const char *) NULL);
    SDL_ShowCursor(0);

    atexit(SDL_Quit);
}

void runGame() {
    running = 1;
   
    while(running) {
        runEvents();
        SDL_Flip(screen);
    }
}

void runEvents() {
    SDL_Event event;
    while(SDL_PollEvent(&event)) {
        switch(event.type) {
            case SDL_QUIT:
                running = 0;
                break;
            default:
                break;
        }
    }
}

